package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Customer;
import br.com.projeto.sakila.bean.Film;

public class FilmDao {

	private SessionFactory sessionFactory;
	private Session session;

	public FilmDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	
	public long buscarFilm(){
		long tempoInicial = System.currentTimeMillis();
		List<Film> listaFilm = new ArrayList<>();
		try{
			session = sessionFactory.openSession();
			 
			listaFilm = session.createQuery("from Film").list();
			
			session.close();
		} catch (Exception e){
			System.err.println("Error : " + e);
		}
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}
	
	public void listarFilm(List<Film> lista){
		System.out.println("---------------------------");
		for (Film film : lista) {
			System.out.println("ID : " + film.getId());
			System.out.println("Title : " + film.getTitle());
			System.out.println("Description : " + film.getDescription());
			System.out.println("Release Year : " + film.getReleaseYear());
			System.out.println("Rental Duration : " + film.getRentalDuration());			
			System.out.println("Length : " + film.getLength());
			System.out.println("Replacement Cost : " + film.getReplacementCost());
			System.out.println("Rating : " + film.getRating());
			System.out.println("Special Features : " + film.getSpecialFeatures());
			//TODO:falta campos

			System.out.println("---------------------------");
		}
	}
}
